﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;

public partial class Movie : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_AddToRentalList_Click(object sender, EventArgs e)
    {
        MembershipUser user = Membership.GetUser();

        if (user != null)
        {

            DVDTableAdapters.RentalListMoviesTableAdapter ta1 = new DVDTableAdapters.RentalListMoviesTableAdapter();
            object ob1 = ta1.CheckMovieOnList(Convert.ToInt32(Request.QueryString["MovieID"]),(Guid)user.ProviderUserKey);

            if (ob1 == null)
            {

                DVDTableAdapters.RentalListMoviesTableAdapter ta = new DVDTableAdapters.RentalListMoviesTableAdapter();


                object ob = ta.GetHighestPriority((Guid)user.ProviderUserKey);
                if (ob != null)
                {
                    short highPrio = Convert.ToInt16(ob);
                    highPrio += 1;
                    ta.InsertRentalList(highPrio, Convert.ToInt32(Request.QueryString["MovieID"]), (Guid)user.ProviderUserKey);
                }

                else
                {
                    short highPrio = 1;
                    ta.InsertRentalList(highPrio, Convert.ToInt32(Request.QueryString["MovieID"]), (Guid)user.ProviderUserKey);
                }
            }
            user = null;
            Response.Redirect("~/RentalOrder.aspx");
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("flagComment"))
        {

            DVDTableAdapters.FlaggedCommentTableAdapter ta = new DVDTableAdapters.FlaggedCommentTableAdapter();
            TableCell CommentID = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0];
            ta.Insert(Convert.ToInt32(CommentID.Text));
            Response.Redirect("~/Thanks.aspx");

        }
    }
}